/*********************************************************************
* File: stringLibrary.cpp
*
* \brief Miscellaneous string functions.
*
* \author Instituto Superior Tecnico de Lisboa, Portugal
* \author Technical University of Lisbon, Portugal
* 
* \author Agentes Autonomos e Sistemas Multiagente
* \author Autonomous Agents and Multiagent Systems
* 
* \version	1.0
* \date		2006/2007
*********************************************************************/
#include "stringLibrary.h"
#include <string.h>
using namespace util;

/**
* \brief Remove leading and trailing blanks from a string.
*
* \param[in] str The string.
**/
void util::strings::trim(char *str)
{
   int pos = 0;
   char *dest = str;

   // skip leading blanks
   while (str[pos] <= ' ' && str[pos] > 0)
      pos++;

   while (str[pos]) {
      *(dest++) = str[pos];
      pos++;
   }

   *(dest--) = '\0'; // store the null

   // remove trailing blanks
   while (dest >= str && *dest <= ' ' && *dest > 0)
      *(dest--) = '\0';
}

/**
* \brief String to bool.
*
* \param[in] str The string.
**/
bool util::strings::atob(const char* str)
{
	if((strcmp(str, "true") == 0) || (strcmp(str, "TRUE") == 0))
		return true;
	else //if((strcmp(str, "false") == 0) || (strcmp(str, "FALSE") == 0))
		return false;
}